package sv.com.bolsaTrabajo.view.bean.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import sv.com.bolsaTrabajo.model.dao.PaisFacade;
import sv.com.bolsaTrabajo.model.entities.Pais;

@FacesConverter(forClass = Pais.class)
public class PaisConvertidor implements Converter {

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
        PaisFacade pf = new PaisFacade();
        Pais p = null;
        try {
            p = pf.encontrarPorID(Integer.parseInt(arg2));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return p;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
        return  ((Pais)arg2).getIdPais().toString();
    }

}
